#include "quit.h"
#include "ui_quit.h"
#include <QKeyEvent>

Quit::Quit(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Quit)
{
    ui->setupUi(this);
    this->setFixedSize(460, 117);
    setWindowTitle(tr("退出熠飞超市收银系统"));

    //设置自定义的鼠标指针图案
    QCursor *myCursor= new QCursor(QPixmap(":/Mouse/Image/mouse/mouse.png"),15,10);
    setCursor(*myCursor);

    QWidget::installEventFilter(this);
}

Quit::~Quit()
{
    delete ui;
}

bool Quit::eventFilter(QObject *target, QEvent *event)
{
    //键盘事件
    if (event->type() == QEvent::KeyPress)
    {
        QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
        if (keyEvent->key() == Qt::Key_Escape)
        {
            this->hide();
            return true;
        }
    }
    if( target == this )
    {
       //窗口停用，变为不活动的窗口
        if(QEvent::WindowDeactivate == event->type())
        {
            this->hide();  //或者关闭窗口,加入自己的操作.
            return true ;
        }
        else
        {
            return false ;
        }
    }
    return QWidget::eventFilter(target, event);
}

void Quit::on_pushButtonConfirmQuit_clicked()
{
    emit exit();
}

void Quit::on_pushButtonCanael_clicked()
{
    this->close();
}
